package com.type;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Parcel;
import android.os.Parcelable;

public class photoByteArray implements Parcelable {
	private byte[] byteArray;

	
	public photoByteArray(byte[] byteArray) {
		this.byteArray = byteArray;
	}
	
	
	public byte[] getPhotoByteArray() {
		return byteArray;
	}
	
	
	public Bitmap toBitmap() {
		return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
	}
	
	
	public photoByteArray(Parcel in) {
	    int length = in.readInt();
	    if (length > 0) {
	        byteArray = new byte[length];
	        in.readByteArray(byteArray);
	    }
	}
	
	
	public static final Parcelable.Creator<photoByteArray> CREATOR = new Parcelable.Creator<photoByteArray>() {
		public photoByteArray createFromParcel(Parcel in) {
			return new photoByteArray(in);
		}

		@Override
		public photoByteArray[] newArray(int size) {
			return new photoByteArray[size];
		}
	};

	
	@Override
	public int describeContents() {
		return 0;
	}

	
	@Override
	public void writeToParcel(Parcel out, int flags) {
		if (byteArray == null)
            out.writeInt(0);
		else {
			out.writeInt(byteArray.length);
			out.writeByteArray(byteArray);
		}
	}
}
